%%% -------------------------------------------------------------------
%%% Author  : tangj
%%% Description :
%%%
%%% Created : 2012-9-22
%%% -------------------------------------------------------------------
-module(gateway_app).
-behaviour(application).
-export([
		 start/2,
		 stop/1,
		 start_tcp/2
		]).

%% --------------------------------------------------------------------
start(_Type, _StartArgs) ->
	io:format("gateway_app start~p~n", [self()]),
	{ok, SupPid} = gateway_sup:start_link(),
	
	AcceptorCount = tool:get_config(gateway, acceptor_count),
	ListenPort = tool:get_config(gateway, port),
	ListenIp = tool:get_config(gateway, ip),
	ok = start_tcp(AcceptorCount, ListenPort),
	
	io:format("node ~p gateway start ~p:~p~n", [node(), ListenIp, ListenPort]),
	{ok, SupPid}.

stop(_State) ->
	ok.

%% 监听accpet
start_tcp(AcceptorCount, Port) ->
	{ok, _Pid} = supervisor:start_child(
				gateway_sup,
				{gateway_server,
				 {gateway_server, start_link, [AcceptorCount, Port]},
				 transient, infinity, worker, [gateway_server]}),
	ok.